home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
Xprof
/
xmeasure
/
timer.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
2KB
|
73 lines
/*==================================================================
* File : timer.c
* Package: Xmeasure
*
* Author : Aloke Gupta.
*
* (C) Copyright 1992, Aloke Gupta.
* All rights granted to University of Illinois Board of Regents.
*==================================================================*/
/* Useful timer functions */
#include <stdio.h>
#include <sys/time.h>
#include "perf.h"
/*
* Convenient functions for measuring elapsed time
*/
static double sync_time = 0.0; /* Synchronization delay */
static double initial_time = 0.0;
SetSyncTime(time)
double time;
{ sync_time = time; }
InitTimer()
{ initial_time = gettime(); }
double TimeSpent() {
double retval;
retval = gettime() - initial_time - sync_time;
if (retval >= 0.0)
return(retval);
else return(0.0);
}
double gettime() /* Return time of the day in seconds since the */
{ /* beginning of this program */
static long initial_sec = -1, initial_usec = -1;
struct timeval tp;
struct timezone tzp;
gettimeofday(&tp, &tzp);
if (initial_sec == -1) {
initial_sec = tp.tv_sec;
initial_usec = tp.tv_usec;
return(0.0);
}
return( (double) (tp.tv_sec -initial_sec) +
((tp.tv_usec - initial_usec) / 1000000.0) );
}
PrintTime(fp)
FILE *fp;
{ struct timeval tp;
struct timezone tzp;
gettimeofday(&tp, &tzp);
fprintf(fp, "%s\n", ctime (&tp.tv_sec) );
}
double getabstime() /* Return time of the day in seconds */
{
struct timeval tp;
struct timezone tzp;
gettimeofday(&tp, &tzp);
return( (double) tp.tv_sec + (tp.tv_usec / 1000000.0) );
}